import cv2 as cv
import matplotlib

matplotlib.use('TkAgg')
from matplotlib import pyplot as plt


def main():
    img = cv.imread('../data/sudoku.png', 0)
    img = cv.medianBlur(img, 5)

    maxValue = 255
    adaptiveMethod = cv.ADAPTIVE_THRESH_MEAN_C
    thresholdType = cv.THRESH_BINARY
    blockSize, C = 11, 2

    th2 = cv.adaptiveThreshold(img, maxValue, adaptiveMethod, thresholdType, blockSize, C)

    titles = ['Original Image', 'Adaptive Mean Threshold']
    images = [img, th2]

    plt.figure(figsize=(15, 15))
    for i in range(2):
        plt.subplot(1, 2, i + 1)
        plt.imshow(images[i], 'gray')
        plt.title(titles[i])
        plt.xticks([])
        plt.yticks([])

    plt.show()


if __name__ == "__main__":
    main()
